package com.cy.pj.common.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class SysTimeAspect {

	@Pointcut("bean(sysRoleServiceImpl)")
	public void doTimeAspect() {}
	
	@Before("doTimeAspect()")
	public void doBefore() {
		System.out.println("@Before+这是Before");
	}
	@After("doTimeAspect()")
	public void doAfter() {
		System.out.println("@After+这是After");
	}
	@AfterReturning("doTimeAspect()")
	public void doAfterReturning() {
		System.out.println("@AfterReturning+这是AfterReturning");
	}
	@AfterThrowing("doTimeAspect()")
	public void doAfterThrowing() {
		System.out.println("@AfterThrowing+这是AfterThrowing");
	}
	
	@Around("doTimeAspect()")
	public Object doAround(ProceedingJoinPoint jp)throws Throwable{
		System.out.println("@Around.before+这是Around环绕通知开始");
		try {
		Object result = jp.proceed();
		System.out.println("@Around.after+这是Around环绕通知结束");
		return result;
		}catch (Exception e) {
			System.out.println("@Around.erception");
			throw e;
		}
	}
}
